package com.ruoyi.oauth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oauth.domain.OauthToken;
import com.ruoyi.oauth.service.IOauthTokenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 授权令牌Controller
 * 
 * @author ruoyi
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/oauth/token")
public class OauthTokenController extends BaseController
{
    @Autowired
    private IOauthTokenService oauthTokenService;

    /**
     * 查询授权令牌列表
     */
    @PreAuthorize("@ss.hasPermi('oauth:token:list')")
    @GetMapping("/list")
    public TableDataInfo list(OauthToken oauthToken)
    {
        startPage();
        List<OauthToken> list = oauthTokenService.selectOauthTokenList(oauthToken);
        return getDataTable(list);
    }

    /**
     * 导出授权令牌列表
     */
    @PreAuthorize("@ss.hasPermi('oauth:token:export')")
    @Log(title = "授权令牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OauthToken oauthToken)
    {
        List<OauthToken> list = oauthTokenService.selectOauthTokenList(oauthToken);
        ExcelUtil<OauthToken> util = new ExcelUtil<OauthToken>(OauthToken.class);
        util.exportExcel(response, list, "授权令牌数据");
    }

    /**
     * 获取授权令牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('oauth:token:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oauthTokenService.selectOauthTokenById(id));
    }

    /**
     * 新增授权令牌
     */
    @PreAuthorize("@ss.hasPermi('oauth:token:add')")
    @Log(title = "授权令牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OauthToken oauthToken)
    {
        return toAjax(oauthTokenService.insertOauthToken(oauthToken));
    }

    /**
     * 修改授权令牌
     */
    @PreAuthorize("@ss.hasPermi('oauth:token:edit')")
    @Log(title = "授权令牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OauthToken oauthToken)
    {
        return toAjax(oauthTokenService.updateOauthToken(oauthToken));
    }

    /**
     * 删除授权令牌
     */
    @PreAuthorize("@ss.hasPermi('oauth:token:remove')")
    @Log(title = "授权令牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oauthTokenService.deleteOauthTokenByIds(ids));
    }
}
